Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 20, 2025

This PR implements wrapped token functionality for the Zap feature, enabling users to provide liquidity using wrapped tokens in addition to native tokens.

Changes Made

Enhanced Token Support

  • Added tokens2 state and fetching from external token API with local fallback
  • Integrated arc200 from ulujs for ARC200 token interactions
  • Implemented comprehensive token data handling with proper error handling

Wrapped Token Balance Calculation

The implementation now supports three types of token balance calculations:

  • Native VOI tokens (tokenId: "0"): Direct account balance minus minimum balance and transaction costs
  • Wrapped tokens: Combined native asset balance + ARC200 balance for accurate total balance
  • Regular ARC200 tokens: Standard ARC200 balance lookup

Transaction Construction Updates

  • Created getTokenId() helper function to resolve correct token IDs for wrapped tokens
  • Updated swap transaction parameters (mA, mB) to handle wrapped token specifics
  • Enhanced deposit transaction parameters (dA, dB) for wrapped token compatibility
  • Maintained full backward compatibility with existing native token functionality

Robust Data Handling

  • Primary token data source: External Tinyman analytics API
  • Fallback mechanism: Local tokens.json for development/offline scenarios
  • Proper data transformation with null character cleanup from token metadata

Technical Implementation

The key innovation is the wrapped token detection logic:

const getTokenId = (currency: Currency) => {
  if (currency?.tokenId === "0") return null; // VOI/native token
  if (!tokens2) return currency?.tokenId;
  
  // For wrapped tokens, find the native asset tokenId
  const wrappedToken = tokens2.find((t) => t.contractId === currency?.contractId);
  return wrappedToken?.tokenId || currency?.tokenId;
};

This ensures that wrapped tokens use the correct native asset token ID in transaction construction while maintaining ARC200 contract compatibility.

Benefits

  • Expands Zap functionality to support wrapped tokens like wVOI
  • Follows established patterns from the Swap component
  • Maintains type safety and error handling
  • No breaking changes to existing functionality
  • Seamless user experience with automatic token type detection
![Zap Interface with Wrapped Token Support](https://github.com/user-attachments/assets/9ca0986b-479f-4a5f-a9f5-a16ac25af414)

The Zap interface now fully supports wrapped token selection and balance calculation, requiring wallet connection for token access as expected.

Fixes #50.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Contributor Author

Copilot AI commented Aug 20, 2025

@temptemp3 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI and others added 2 commits August 20, 2025 20:46
Co-authored-by: temptemp3 <23183451+temptemp3@users.noreply.github.com>
Co-authored-by: temptemp3 <23183451+temptemp3@users.noreply.github.com>
Copilot AI changed the title [WIP] HumbleSwap: Add zap Add wrapped token support to Zap feature Aug 20, 2025
Copilot AI requested a review from temptemp3 August 20, 2025 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HumbleSwap: Add zap

2 participants